<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Encode character to HTML numeric string reference</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mb-encode-numericentity" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_encode_numericentity</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">mb_encode_numericentity</span> &mdash; <span class="dc-title">Encode character to HTML numeric string reference</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-encode-numericentity-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_encode_numericentity</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$convmap</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code><span class="initializer"> = mb_internal_encoding()</span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$is_hex</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
  ]] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Converts
   specified character codes in <span class="type"><a href="language.types.string.html" class="type string">string</a></span> <code class="parameter">str</code>
   from character code to HTML numeric character reference.    
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-encode-numericentity-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       The <span class="type"><a href="language.types.string.html" class="type string">string</a></span> being encoded.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">convmap</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">convmap</code> is array specifies code area to
       convert.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para"><code class="parameter">encoding</code>
参数为字符编码。如果省略，则使用内部字符编码。</p>
     </dd>

    
    
     <dt>
<code class="parameter">is_hex</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.mb-encode-numericentity-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The converted <span class="type"><a href="language.types.string.html" class="type string">string</a></span>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mb-encode-numericentity-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.4.0</td>
       <td>
        Added <code class="parameter">is_hex</code> parameter.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-encode-numericentity-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3183">
    <p><strong>Example #1 <code class="parameter">convmap</code> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$convmap&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(<br />&nbsp;</span><span style="color: #0000BB">int&nbsp;start_code1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;end_code1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;offset1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;mask1</span><span style="color: #007700">,<br />&nbsp;</span><span style="color: #0000BB">int&nbsp;start_code2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;end_code2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;offset2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;mask2</span><span style="color: #007700">,<br />&nbsp;........<br />&nbsp;</span><span style="color: #0000BB">int&nbsp;start_codeN</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;end_codeN</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;offsetN</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">int&nbsp;maskN&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;Specify&nbsp;Unicode&nbsp;value&nbsp;for&nbsp;start_codeN&nbsp;and&nbsp;end_codeN<br />//&nbsp;Add&nbsp;offsetN&nbsp;to&nbsp;value&nbsp;and&nbsp;take&nbsp;bit-wise&nbsp;'AND'&nbsp;with&nbsp;maskN,&nbsp;then<br />//&nbsp;it&nbsp;converts&nbsp;value&nbsp;to&nbsp;numeric&nbsp;string&nbsp;reference.<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-encode-numericentity-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3184">
    <p><strong>Example #2 <span class="function"><strong>mb_encode_numericentity()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Convert&nbsp;Left&nbsp;side&nbsp;of&nbsp;ISO-8859-1&nbsp;to&nbsp;HTML&nbsp;numeric&nbsp;character&nbsp;reference&nbsp;*/<br /></span><span style="color: #0000BB">$convmap&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">0x80</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xff</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xff</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mb_encode_numericentity</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$convmap</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"ISO-8859-1"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Convert&nbsp;user&nbsp;defined&nbsp;SJIS-win&nbsp;code&nbsp;in&nbsp;block&nbsp;95-104&nbsp;to&nbsp;numeric<br />&nbsp;&nbsp;&nbsp;string&nbsp;reference&nbsp;*/<br /></span><span style="color: #0000BB">$convmap&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe000</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe03e</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x1040</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe03f</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe0bb</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x1041</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe0bc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe0fa</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x1084</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe0fb</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe177</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x1085</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe178</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe1b6</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x10c8</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe1b7</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe233</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x10c9</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe234</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe272</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x110c</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe273</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe2ef</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x110d</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe2f0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe32e</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x1150</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">0xe32f</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xe3ab</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x1151</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0xffff&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mb_encode_numericentity</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$convmap</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"sjis-win"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-encode-numericentity-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mb_decode_numericentity.html" class="function" rel="rdfs-seeAlso">mb_decode_numericentity()</a> - 根据 HTML 数字字符串解码成字符</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>